use "/Users/ethanboldt/Dropbox/BVB Judical Nom Comm/JLC submission/R&R revisions/Data/model file.dta"

*Table 1 Summary Statistics
*All Applicants (Model 1 data)
*Note: Several vacancies are excluded from each model because of a lack of variation in the dependent variable (all applicants appointed or refused)
summarize aptdummy experience sq_exp median_lsat juddummy  pubpvt instatel   female black  n_times_applied_4_judgeships number_applicants year if !missing(experience) & !missing(black) &!missing(median_lsat) &!missing(juddummy) &!missing(female) & posid!=30096  & posid!=30234  & posid!=30251  & posid!=30254  & posid!=30256  & posid!=30259  & posid!=30260  & posid!=30261  & posid!=30262  & posid!=30264  & posid!=30274  & posid!=40032  & posid!=40095  & posid!=40135  & posid!=40125  & posid!=40140  & posid!=40141  & posid!=40147  & posid!=40153
*Subset of applicants merged with DIME(Model 2 data)
summarize aptdum gov_nom gov_timely experience sq_exp median_lsat juddummy  pubpvt instatel   female black  n_times_applied_4_judgeships number_applicants year if !missing(experience) & !missing(black) &!missing(median_lsat) &!missing(juddummy) &!missing(female) & !missing(gov_nom_i) & !missing(gov_timely) & model2_listwise!=1 &!missing(posid)
*Applicants with DIME and imputed CFScores (Model 3 data)
summarize aptdum imputed_gov_nom_ideo_distance gov_timely experience sq_exp median_lsat juddummy  pubpvt instatel   female black  n_times_applied_4_judgeships number_applicants year if !missing(experience) & !missing(black) &!missing(median_lsat) &!missing(juddummy) &!missing(female) & !missing(imputed_gov_nom_ideo_distance) & !missing(gov_timely) & model3_listwise!=1 &!missing(posid)
	  
	  
*Footnote 10
*2,853 missing an ideology score
count if missing(gov_nom_i)
*1,982 observations remain
tab footnote10 if !missing(gov_nom)
*1,091 listwise deleted for predicting outcomes perfectly for a given vacancy in Model 2


*Figure 1: Bivariate Logistic Regression of Ideological Distance on Appointmnet)
logit aptdummy gov_nom_ideo_distance  i.posid if bivariate_posid_missing!=1
*an applicant who is closest to the sitting governor's ideology has a probability of appointment of 0.172 indicative of a better than average chance of appointment. By contrast, the most ideologically distant applicant from the governor has a probability of appointment is just 0.033 (a decrease in probability of 0.139).
*min max below for the bivariate analysis
summarize gov_nom if bivariate_posid_missing!=1
*probabilities
margins, at(gov_nom=( .0012944 2.170001))

margins, at(gov_nom=(0(.01)2.17)) 
marginsplot,  legend(off) title("")  addplot(scatter graph_aptdummy gov_nom_, msymbol(smx) xlabel(0(.2)2.2,gmin gmax) ylabel(0(.025).225, angle(0) grid gmin gmax)) recastci(rarea) recast(line) xtitle(Applicant CFScore Ideological Distance from Governor)  ytitle(Probability of Appointment to Judgeship)  ciopts(color(gs12))  graphregion(color(white))

*Table 2: Crosstabulation of Donating to Governor and Appointment
tab gov_timely aptdummy, row 


*Table 3: Model 1
*the fixed effects result in some vacancies having no variation in the dependent variable and thus the notes that appear above the output
logit aptdummy  experience sq_exp  median_lsat i.juddummy  i.pubpvt i.instatel   i.female i.black  n_times_applied_4_judgeships i.posid 

*The predicted probability of receiving an appointment based on having been a Judge is approximately 0.198 while those who have no prior service as a judge have a nearly 0.051 probability of appointment. 
margins juddummy
*The prestige of an applicant's legal education, as measured by the Median LSAT score of the law school they attended, significantly influences whether they will be appointed. The predicted probability of being appointed ranges from approximately 0.04 at the minimum score to approximately 0.101 at the maximum score. 
margins, at(median_lsat=(145 173))
*The impact of attending a Georgia Law School is statistically significant. Those who attended an in-state institution are slightly more likely to receive an appointment relative to those who did not (a change in probability from 0.053 to 0.069). 
margins instatel
*African American applicants have a slightly increased predicted probability of receiving an appointment, roughly 0.02 greater than other individuals.
margins black
*Robustness check of conditional logit for Model 1
clogit aptdummy experience sq_exp  median_lsat i.juddummy  i.pubpvt i.instatel   i.female i.black  n_times_applied_4_judgeships  , group(posid)

*Table 3: Model 2
logit aptdummy c.gov_nom_ideo_distance   i.gov_timely_donor experience sq_exp  median_lsat i.juddummy  i.pubpvt i.instatel   i.female i.black  n_times_applied_4_judgeships i.posid if model2_listwise!=1

*min to max effect of ideological distance (direct measure)
margins, at(gov_nom=(.001 2.17)) 
*one standard dev increase from min
margins, at(gov_nom=(.001 .39)) 
*effect of donating to sitting governor's campaign
margins gov_timely_donor
*effect of prior judicial service
margins juddummy
*min to max effect of median lsat score for law school attended
margins, at(median_l=(145 173)) 

*Figure 2: Left Pane
*margins
margins, at(gov_nom=(.001 (.01)2.17))
marginsplot, ylabel(0(.02).2, angle(0) grid gmin gmax)  xlabel(0(.25)2.5) xtitle(Applicant CFScore Ideological Distance from Governor) title(Model 2) ytitle(Probability of Appointment to Judgeship) addplot(scatter graph_aptdummym2 gov_nom_ideo_distance, msymbol(smx) ylabel(0(.02).2) xlabel(0(.25)2.5))  recastci(rarea) ciopts(color(gs12)) recast(line) legend(off) graphregion(color(white)) 
graph save "model2.gph", replace
*Robustness check of conditional logit for Model 2
clogit aptdummy c.gov_nom_ideo_distance   i.gov_timely_donor experience sq_exp  median_lsat i.juddummy  i.pubpvt i.instatel   i.female i.black  n_times_applied_4_judgeships , group(posid)


*Table 3: Model 3
*the fixed effects result in some vacancies having no variation in the dependent variable and thus the notes that appear above the output
logit aptdummy imputed  i.gov_timely_donor experience sq_exp  median_lsat i.juddummy  i.pubpvt i.instatel   i.female i.black  n_times_applied_4_judgeships i.posid  

*min to max effect of ideological distance (imputed measures for those attorneys missing ideology scores)
margins, at(imputed=(.001 2.457))
*one standard dev increase from min
margins, at(imputed=(.001 .402))
*effect of attending in state law school
margins instatel
*effect of donating to sitting governor's campaign
margins gov_timely_donor
*effect of prior judicial service
margins juddummy
*min to max effect of median lsat score for law school attended
margins, at(median_l=(145 173)) 

*Figure 2: Right Pane
margins, at(imputed=(.001(.01)2.461)) 
marginsplot, ylabel(0(.02).2, angle(0) grid gmin gmax)  xlabel(0(.25)2.5) xtitle(" ") title(Model 3) ytitle(Probability of Appointment to Judgeship) addplot(scatter graph_aptdummym3 imputed, msymbol(smx) ylabel(0(.02).2) xlabel(0(.25)2.5))  recastci(rarea) ciopts(color(gs12)) recast(line) legend(off) graphregion(color(white)) 
graph save "model3.gph", replace

*Figure 2 (Some formatting changes were made in graph editor by hand)
graph combine "model2.gph" "model3.gph"


